package service;

import JDBC.DBUtils;
import com.google.gson.JsonObject;
import method.AccountBuyInformation;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
import java.sql.Timestamp;
/**
 * @author Gao Shiwei
 * this calss has been given up
 */
@WebServlet(name = "TransportState")
public class TransportState extends HttpServlet {
    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String ItemID=req.getParameter("ItemID");
        String PhoneNumber=req.getParameter("PhoneNumber");
        String mill=req.getParameter("CreateTime");
        long Mill=Long.parseLong(mill);
        //AccountBuyInformation[] BuyInformation= DBUtils.QueryAccountBuyOneInformation(ItemID,PhoneNumber,Mill);
        //Timestamp time=BuyInformation[0].getCreateTime();
        //long mill=time.getTime();
        Timestamp d = new Timestamp(System.currentTimeMillis());
        long current=d.getTime();
        System.out.println(d);
        long hour=(current-Mill)/60/1000;
        if(hour<=10){
            JsonObject Container=new JsonObject();
            Container.addProperty("answer","The shopkeeper hasn't delivered yet");
            PrintWriter out = resp.getWriter();
            out.println(Container);
            out.flush();
            out.close();
        }else if(hour>10&&hour<=20){
            JsonObject Container=new JsonObject();
            Container.addProperty("answer","The goods are in transit");
            PrintWriter out = resp.getWriter();
            out.println(Container);
            out.flush();
            out.close();
        }else{
            JsonObject Container=new JsonObject();
            Container.addProperty("answer","Goods arrived");
            PrintWriter out = resp.getWriter();
            out.println(Container);
            out.flush();
            out.close();
        }
    }

}
